home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 4509 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: cs.ruu.nl!usenet
  2. From: wsldanke@cs.ruu.nl (Wessel Dankers)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: x ^= y ^= x ^= y;
  5. Date: 29 Feb 96 20:31:48 +0100
  6. Organization: Dept of Computer Science, Utrecht University, The Netherlands
  7. Message-ID: <2099.6633T1231T2431@cs.ruu.nl>
  8. References: <1286.6624T1439T237@cs.ruu.nl> <3Du8y*20g@yaps.rhein.de>
  9.     <3132C4BE.2D60@cs.ruu.nl> <4h3ivp$966@hasle.sn.no>
  10. NNTP-Posting-Host: anx1p3.cc.ruu.nl
  11. X-Newsreader: THOR 2.22 (Amiga TCP/IP)
  12.  
  13. Jakob Rivertz <jakob.rivertz@aftenposten.no> wrote:
  14. > In article <3132C4BE.2D60@cs.ruu.nl>, Wessel Dankers <wsldanke@cs.ruu.nl>
  15. > wrote:
  16. >>Arno Eigenwillig wrote:
  17. >>> In article <1286.6624T1439T237@cs.ruu.nl>, Wessel Dankers writes:
  18. >>> > Which can of course be rewritten as:
  19. >>> >  x ^= y;
  20. >>> >  y ^= x;
  21. >>> >  x ^= y;
  22. >>> Yes.
  23. >>> > or if you want it real fancy:
  24. >>> >  x ^= y ^= x ^= y;
  25. >>> No. Reread your C text book and find out about sequence points, side
  26. >>> effects, and which combinations of them are not allowed.
  27. >>If you would have taken a quick peek yourself you would have seen that an
  28. >>assignment has a return-value of itself. Anyway, I tested it and it worked.
  29.  
  30. > Leave this guy alone, everyone. It's is a troll.
  31.  
  32. Don't blame the guy in my .sig, he can't help it.
  33.  
  34. > For those of you who have been misleaden by these posts, do get the
  35. > comp.lang.c-faq, read questions 4.1 through 4.6, and 6.1 (which discusses
  36. > this very example). You are not allowed to modify the same value twice
  37. > between sequence points. Sequence points are implied by `&&', `||', `,',
  38. > `? :' and `;'. For example:
  39.  
  40. > <never use these>
  41. >         a[i] = i++;
  42. >         j = i++ * i++;
  43. >         x ^= y ^= x ^= y;
  44. >         i = ++i;
  45. > </never use these>
  46.  
  47. I.e. you can't assume anything about the order in which a statement is
  48. evaluated. So, if I write:
  49. printf("%d", time(NULL));
  50. my compiler could very well first print the time and then ask the system what
  51. time it is. Interesting thought. So, if I have the right compiler I can
  52. compute PI in 1,000,000,000,000 decimals in 0 seconds, and then sneekily
  53. switch off the computer when it's about to actually calculate PI. Hmmm..
  54.  
  55. Well, if it's in the FAQ it must be true...
  56.  
  57. --
  58. Wessel Dankers                 _\\|//_            <wsldanke@cs.ruu.nl>
  59.                                ///|\\\
  60. ----------------------------oOO--(_)---OOo----------------------------
  61. `Never imagine yourself not to be otherwise than what it might appear
  62. to others that what you were or might have been was not otherwise than
  63. what you had been would have appeared to them to be otherwise.'
  64.  
  65.